package com.houtai.service.resume;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houtai.base.RetInfo;
import com.houtai.bean.TdResume;
import com.houtai.bean.dto.resume.TdResumeListDto;
import com.houtai.bean.vo.resume.TdResumeDetail;
import com.houtai.common.util.LogUtils;
import com.houtai.dao.TdJobExperienceDao;
import com.houtai.dao.TdProjectExperienceDao;
import com.houtai.dao.TdResumeDao;
import com.houtai.dao.TsJzAdminOperationDao;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ResumeService {
    private static Logger logger = Logger.getLogger(ResumeService.class);
    @Autowired
    private TdResumeDao tdResumeDao;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private TsJzAdminOperationDao tsJzAdminOperationDao;
    @Autowired
    private TdProjectExperienceDao tdProjectExperienceDao;
    @Autowired
    private TdJobExperienceDao tdJobExperienceDao;
    /**
     * @Purpose   查找简历列表
     * @param     page
     * @version   1.0
     * @author    李准
     * @time      2017-08-19
     * @return    RetInfo
     */
    public RetInfo findTdResume(TdResumeListDto page, HttpServletRequest request) {
        String logInfo = this.getClass().getName() + ":findTdResume:";
        RetInfo retInfo = new RetInfo();
        logger.info("======" + logInfo + "begin======");
        try {
            PageHelper.startPage(page.getCurrent_page(), page.getPage_size(), "resume_id desc");
            List<TdResume> lists = tdResumeDao.findTdResume(page);
            PageInfo<TdResume> list = new PageInfo<>(lists);
            Map<String, Object> map = new HashMap<>();
            map.put("list", list.getList());
            map.put("total_page", list.getPages());
            map.put("total_record", list.getTotal());
            map.put("current_page", list.getPageNum());
            map.put("page_size", list.getPageSize());
            map.put("user_name", page.getUser_name());
            map.put("phone_no", page.getPhone_no());
            retInfo.setMark("0");
            retInfo.setTip("成功");
            retInfo.setObj(map);
            LogUtils.AdminOperation(redisTemplate ,tsJzAdminOperationDao,"查找简历列表" , request);

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");

        return retInfo;
    }
    /**
     * @Purpose   查找简历详情
     * @param     resume_id
     * @version   1.0
     * @author    李准
     * @time      2017-08-19
     * @return    RetInfo
     */
    public RetInfo findTdResume(int resume_id, HttpServletRequest request) {
        String logInfo = this.getClass().getName() + ":findTdResume:";
        RetInfo retInfo = new RetInfo();
        logger.info("======" + logInfo + "begin======");
        try {
            Map<String, Object> map = new HashMap<>();
            TdResumeDetail tdResumeDetail = tdResumeDao.findTdResumeDetail(resume_id);
            map.put("jobs", tdJobExperienceDao.findTdJobExperienceList(tdResumeDetail.getResume_id()));
            map.put("projects", tdProjectExperienceDao.findTdProjectExperienceList(tdResumeDetail.getResume_id()));
            map.put("resume", tdResumeDetail);
            retInfo.setMark("0");
            retInfo.setTip("成功");
            retInfo.setObj(map);
            LogUtils.AdminOperation(redisTemplate ,tsJzAdminOperationDao,"查找简历详情" , request);

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");

        return retInfo;
    }

}
